package com.nbicc.dp.web.widgetinstancevalue.controller;

import com.nbicc.core.common.ObjectPacking;
import com.nbicc.db.modular.dp.widgetinstancevalue.model.WidgetInstanceValueImpl;
import com.nbicc.dp.web.widgetinstancevalue.dtoservice.WidgetInstanceValueDtoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author: lilingyan
 */
@Api(value = "dp:组件所有数据点值" , description = "")
@RestController
@RequestMapping("/widget/instance/value")
public class WidgetInstanceValueController {

    @Autowired
    private WidgetInstanceValueDtoService widgetInstanceValueDtoService;

    @ApiOperation(value = "按控件id查询它所有的值")
    @GetMapping("widgetInstanceId/{widgetInstanceId}")
    public ResponseEntity<ModelMap> selectByWidgetClassId(@PathVariable Integer widgetInstanceId){
        return widgetInstanceValueDtoService.selectByWidgetClassId(widgetInstanceId);
    }

    @ApiOperation(value = "设置控件有多少值(全量覆盖)" , notes = "第二次设置会清除所有第一次设置的;id自动生成")
    @PostMapping("/setAllWidgetInstanceValue/{widgetInstanceId}")
    public ResponseEntity<ModelMap> setAllWidgetInstanceValue(
            @PathVariable Integer widgetInstanceId ,
            @RequestBody ObjectPacking<List<WidgetInstanceValueImpl>> listObjectPacking){
        return widgetInstanceValueDtoService.setAllWidgetInstanceValue(widgetInstanceId , listObjectPacking.getData());
    }

    @ApiOperation(value = "更新控件数据", notes = "以id(必传)")
    @PutMapping("updateAllWidgetInstanceValueById/{widgetInstanceId}")
    public ResponseEntity<ModelMap> updateAllWidgetInstanceValueById(
            @PathVariable Integer widgetInstanceId ,
            @RequestBody ObjectPacking<List<WidgetInstanceValueImpl>> listObjectPacking){
        return widgetInstanceValueDtoService.updateAllWidgetInstanceValueById(widgetInstanceId , listObjectPacking.getData());
    }

    @ApiOperation(value = "删除", notes = "以控件id")
    @DeleteMapping("/deleteByWidgetInstanceId/{widgetInstanceId}")
    public ResponseEntity<ModelMap> deleteByWidgetInstanceId(@PathVariable Integer widgetInstanceId){
        return widgetInstanceValueDtoService.deleteByWidgetInstanceId(widgetInstanceId);
    }

}
